//请求路径常量
import * as req_con from '../../utils/constant'
//数据
import {user,userInfo} from '../sql_data/data'
export let loginDao = (url,params) => {
    //模仿数据库CRUD操作
    switch (url) {
        //Login
        case req_con.LOGINGET:
            return findUser(params)
        case req_con.LAYOUTGET:
            return findUserInfo(params)
        default:
            break;
    }
}


//登录时用户查询
let findUser = (params) => {
    console.log(params);
    let loginId = params.loginId
    let loginPwd = params.loginPwd
    let data = {}
    user.every(v=>{
        if(v.loginId===loginId){
            if(v.loginPwd===loginPwd){
                data = {success:true,token:'测试token'}
                return false
            }
            else {
                data = {success:false,message:'密码错误'}
                return false
            } 
        }else{
            data = {success:false,message:'用户名不存在'}
            return true
        }
    })
    return data;
}

//Layout查询用户具体信息
let findUserInfo = (params) => {
    let loginId = params.loginId
    let data = {}
    userInfo.every(v=>{
        if(v.loginId===loginId){
            data = v
            return false
        }
        return true
    })
    return data;
}